'use strict';

	var app = angular.module('app');
    app.controller('bmHouseUpdateController', ['$scope', '$rootScope', '$state', '$timeout', 'toaster','$modal',
        function($scope, $rootScope, $state, $timeout, toaster, $modal) {
        	$scope.record = {};//防止ie浏览器报没有未定义而进行属性的赋值
        	$scope.record = {
        		bmBiBuilding:{},
        		bmBiSeat:{},
        		bmBiFloor:{},
        		biHouseinfo:{
        			regionid:$state.params.regionId
        		},
        		regionName:$state.params.regionName
        	};
        	$scope.stateRegionId = $state.params.regionId;
        	$scope.stateRegionName = $state.params.regionName;
        	$scope.title="新增房屋信息";
        	if($state.includes('**.update')){
                $scope.title="修改房屋信息";
                $scope.reset = false;//修改不允许重置
                var id = $state.params.id;
                $scope.record.houseid = id;
                activate(id);
            }else if($state.includes('**.create')){
            	 $scope.title="新增房屋信息";
            	 $scope.reset = true;//新增时可以重置
            }
        	
        	validate();
        	//重置表单
			$scope.resetFrom = function(){
			   $scope.record = {
	        		bmBiBuilding:{},
	        		bmBiSeat:{},
	        		bmBiFloor:{},
	        		biHouseinfo:{
	        			regionid:$state.params.regionId
	        		},
        			regionName:$state.params.regionName
        		};
			}
        	$scope.submit= function(){
        	    //将页面上的字段拼接到房屋地址保存到数据库
        		$scope.record.biHouseinfo.address = $scope.record.bmBiBuilding.buildingaddress + $scope.record.biHouseinfo.houseNum
                //console.log($scope.record.address);
                var m = $scope.record;
                if(m){
                    $scope.isDisabled = true;
                    $.ajax({
          				    type: 'POST',
          	          dataType: 'json',
          				    contentType:'application/json;charset=UTF-8',
          				    url : '/dac/bm/house/insertOrUpdate',
          				    data: angular.toJson($scope.record)
        			     }).then(function(result){
                      if(result.httpCode ==200){//成功
                            toaster.clear('*');
                            toaster.pop('success', '', "保存成功");
                            $timeout(function(){
                                $state.go("main.bm.house.list", $state.params);
                            },2000);
                        }else{
                            toaster.clear('*');
                            toaster.pop('error', '', result.msg);
                            $scope.isDisabled = false;
                      }
                });
              }
                
            }
        	
        	
        	// 初始化页面
            function activate(id) {
    	        $scope.loading = true;
            	$.ajax({
            		type: 'PUT',
    				url : '/dac/bm/house/detail',
    	            dataType: 'json',
    				contentType:'application/json;charset=UTF-8',
    				data: angular.toJson({'id': id})
    			}).then(function(result) {
    				$scope.loading = false;
    				if (result.httpCode == 200) {
    					$scope.record = result.data;
    					console.log(result.data)
    					if($scope.record.bmBiBuilding == null){
                    		$scope.record.bmBiBuilding={};
                    	}
    					if($scope.record.bmBiSeat == null){
    						$scope.record.bmBiSeat={};
    					}
    					if($scope.record.bmBiFloor == null){
    						$scope.record.bmBiFloor={};
    					}
    				} else {
    					toaster.clear('*');
                        toaster.pop('error', '', result.msg);
                        $scope.isDisabled = true;
    				}
    				$scope.$apply();
    				
    			});
            }
            
            $scope.loadHouseStatus = function () {
                $scope.param = {};
                $scope.param.type='HOUSESTATUS';
                $.ajax({
                    type: 'PUT',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
                    url : '/dic/queryDicListByType',
                    data: angular.toJson($scope.param)
                }).then(function(result) {
                    if (result.httpCode == 200) {
                        $scope.record.biHouseinfo.status = '1';//房屋状态默认为出租
                        $scope.houseStatus = result.data;
                        $scope.$apply();
                    }
                });
            }
            $scope.loadHouseStatus();

        	function validate(houseid){
                jQuery('form').validate({
                	rules: {
                        jwqdm:{
                            required:true,
                        },

                        jwqmc:{
                            required:true,
                        },

                        buildingname:{
                            required: true,
                        },

                        houseNum:{
                            required :true,
                        },
                		    houseName: {
                           required: true,
                           maxLengthB:[20]
            			      },
                        houseCode: {
                            required: true,
                            maxLengthB:[10]
             			      },
                        address: {
                            required: true,
                            maxLengthB:[50]
             			      },
                        pidcardno: {
                            required: true,
             				         number:true
             			      },
                        propertyrightcard:{
             				     number:true
             			      },
                        longitude:{
             				     number:true
             			      },
                        latitude:{
             				     number:true
             			      },
                        committee:{
                            required:true
                        }
                   },
                   messages: {
                       jwqdm:{
                           required : '请填写警务区代码',
                       },

                       jwqmc:{
                           required : '请填写警务区名称',
                       },

                       buildingname: {
                           required : '请填写楼栋名称',
                       },

                       houseNum:{
                           required : '请填写房号',
                       },
                	     houseName: {
                           required: '请填写房屋名称',
                           maxLengthB:"房屋名称长度不能大于{0}位"
                   	   },
                       houseCode: {
                           required: '请填写房屋编码',
                           maxLengthB:"房屋编码长度不能大于{0}位"
                   	   },
                       address: {
                           required: '请填写房屋地址',
                           maxLengthB:"房屋地址长度不能大于{0}位"
                   	   },
                       pidcardno: {
                           required:'请输入身份证号',
                           number:'输入必须为数字'
            			},
                       propertyrightcard:{
                            number:'输入必须为数字'
            			},
                       longitude:{
             				number:'输入必须为数字'
             			},
                       latitude:{
             				number:'输入必须为数字'
             			},
                       committee:{
                           required:'请填写居委会'
                       }
                   },
                    submitHandler: function() {
                        $scope.submit();
                    }
                });
            }
               //楼栋新增模态框
            $scope.openInsertBuilding = function() {
                var modalInstance = $modal.open({
                    templateUrl : 'bmBuildingInsert.html',// script标签中定义的id
                    controller : 'bmBuildingInsertCtrl',// modal对应的Controller
                    size: 'lg',
                    resolve : {
                        regionid : function() {  
                            return $scope.record.biHouseinfo.regionid;
                        }  
                    }
                });
                modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数
                     
                });  
                modalInstance.result.then(function(result) { 
                   $scope.record.bmBiBuilding = result;
                   $scope.record.biHouseinfo = result;//将regionid、buildingid绑定到biHouseinfo
                   /*console.log(result);
                   console.log($scope.record.biHouseinfo);*/
                }, function(reason) {  
//                    console.log(reason);  
                });
                validate();
            };
            
            //楼座新增模态框
            $scope.openInsertSeat = function() {
                var modalInstance = $modal.open({
                    templateUrl : 'bmSeatInsert.html',// script标签中定义的id
                    controller : 'bmSeatInsertCtrl',// modal对应的Controller
                    size: 'lg',
                    resolve : {
                        items : function() {  
                            var items = {};
                            items.regionid = $scope.record.biHouseinfo.regionid;
                            items.buildingid = $scope.record.biHouseinfo.buildingid;
                            return items;f
                        }  
                    }
                });
                modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数
                     
                });  
                modalInstance.result.then(function(result) { 
                   $scope.record.bmBiSeat = result;
                   $scope.record.biHouseinfo = result;//将regionid、buildingid、seatid绑定到biHouseinfo
                   /*console.log(result);
                   console.log($scope.record.biHouseinfo);*/
                }, function(reason) {  
//                    console.log(reason);  
                });

                validate();
            };
            
          //楼层新增模态框
            $scope.openInsertFloor = function() {
                var modalInstance = $modal.open({
                    templateUrl : 'bmFloorInsert.html',// script标签中定义的id
                    controller : 'bmFloorInsertCtrl',// modal对应的Controller
                    size: 'lg',
                    resolve : {
                        items : function() {  
                            var items = {};
                            items.regionid = $scope.record.biHouseinfo.regionid;
                            items.buildingid = $scope.record.biHouseinfo.buildingid;
                            items.seatid = $scope.record.biHouseinfo.seatid;
                            return items;
                        }  
                    }
                });
                modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数
                     
                });  
                modalInstance.result.then(function(result) { 
                    $scope.record.bmBiFloor = result;
                    $scope.record.biHouseinfo = result;////将regionid、buildingid、seatid、floorid绑定到biHouseinfo
                    /*console.log(result);
                    console.log($scope.record.biHouseinfo);*/
                }, function(reason) {  
//                    console.log(reason);  
                }); 
            };
            
            //地市模态框
            $scope.showCityList = function() {
                $scope.items = [];
                   var modalInstance = $modal.open({
                       templateUrl : 'bmCityList.html',//script标签中定义的id
                       controller : 'bmCityListCtrl',//modal对应的Controller
                       size: 'lg',
                       resolve : {
                           items : function() {  
                               var items = {};
                               items.parent_code = $scope.record.biHouseinfo.cityCode;
                               return items;
                           }
                       }
                   });
                   
                   modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                        
                   });  
                   modalInstance.result.then(function(result) { 
                    
                    $scope.record.biHouseinfo.cityId = result[0];
                    $scope.record.biHouseinfo.cityName = result[1];
                    $scope.record.biHouseinfo.cityCode = result[2];
                   }, function(reason) {  
                       console.log(reason);  
                   }); 

               };
               
               //区县模态框
               $scope.showAreaList = function() {
                    $scope.items = [];
                      var modalInstance = $modal.open({
                          templateUrl : 'bmAreaList.html',//script标签中定义的id
                          controller : 'bmAreaListCtrl',//modal对应的Controller
                          size: 'lg',
                          resolve : {
                              items : function() {  
                                     var items = {};
                                     items.parent_code = $scope.record.biHouseinfo.cityCode;
                                     return items;
                              }
                          }
                      });
                      
                      modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                           
                      });  
                      modalInstance.result.then(function(result) { 
                    
                        $scope.record.biHouseinfo.areaId = result[0];
                        $scope.record.biHouseinfo.areaName = result[1];
                        $scope.record.biHouseinfo.areaCode = result[2];
                      }, function(reason) {  
                          console.log(reason);  
                      }); 

                  };
               
                  //乡镇街道模态框
                  $scope.showStreetList = function() {
                        $scope.items = [];
                         var modalInstance = $modal.open({
                             templateUrl : 'bmStreetList.html',//script标签中定义的id
                             controller : 'bmStreetListCtrl',//modal对应的Controller
                             size: 'lg',
                             resolve : {
                               items : function() {  
                                      var items = {};
                                      items.parent_code = $scope.record.biHouseinfo.areaCode;
                                      return items;
                                 }
                             }
                         });
                         
                         modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                              
                         });  
                         modalInstance.result.then(function(result) { 
                        
                            $scope.record.biHouseinfo.streetId = result[0];
                            $scope.record.biHouseinfo.streetName = result[1];
                            $scope.record.biHouseinfo.streetCode = result[2];
                         }, function(reason) {  
                             console.log(reason);  
                         }); 

                     };
                 //警务区的模态框
                 $scope.openjwqdm = function() {
                     var modalInstance = $modal.open({
                         templateUrl : 'jwq.html',// script标签中定义的id
                         controller : 'jwqModalCtrl',// modal对应的Controller
                         size : 'lg'
                         // resolve : {
                         //     personType : function() {// 向模态框app中传递参数
                         //        return $scope.record.personType;
                         //     }
                         // }
                     });
                     //选择之后回显到页面上来
                     modalInstance.result.then(function(result) {//这里的result是下面的模态回调函数的值
                         $scope.record.biHouseinfo.policeareaid = result[1];
                         $scope.record.biHouseinfo.policeareaname = result[2];
                     }, function(reason) {
                         console.log(reason);
                     });

                 };

        	 $scope.showBuildingList = function() {
      		 	$scope.items = [];
                   var modalInstance = $modal.open({
                       templateUrl : 'bmBuildingList.html',//script标签中定义的id
                       controller : 'bmBuildingListCtrl',//modal对应的Controller
                       size: 'lg',
                       resolve : {
                      	 regionId : function() {  
                               return $scope.record.biHouseinfo.regionid;  
                           }
                       }
                   });
                   
                   modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                        
                   });  
                   modalInstance.result.then(function(result) { 
                	
                 	if((result[0] != null || result[0] != '')&&$scope.record.bmBiBuilding.buildingid != result[0]){
                       	$scope.record.biHouseinfo.seatid = '';
                        $scope.record.bmBiSeat.seatname='';
                        
                        $scope.record.biHouseinfo.floorid = '';
                        $scope.record.bmBiFloor.floorname='';
                     }
                   	$scope.record.biHouseinfo.buildingid = result[0];
                   	$scope.record.bmBiBuilding.buildingname=result[1];
                   	$scope.record.bmBiBuilding.buildingaddress=result[2];

                   }, function(reason) {  
                       console.log(reason);  
                   }); 

               };
               
               $scope.showSeatList = function() {
//             	 if($scope.record.biHouseinfo.buildingid == null || $scope.record.biHouseinfo.buildingid == ''){
//           			alert('请选择楼栋');
//           			$('#houseName').focus();
//           			return;
//             	 }
                     var modalInstance = $modal.open({
                         templateUrl : 'bmSeatList.html',//script标签中定义的id
                         controller : 'bmSeatListCtrl',//modal对应的Controller
                         size: 'lg',
                         resolve : {
                        	 regionId : function() {  
                                 return $scope.record.biHouseinfo.regionid;  
                             },
                          buildingId : function(){
                         	 	return $scope.record.biHouseinfo.buildingid;
                          	},
                         }
                     });
                     
                     modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                          
                     });  
                     modalInstance.result.then(function(result) { 
                     	$scope.record.bmBiSeat = {};
                     	$scope.record.biHouseinfo.seatid = result[0];
                     	$scope.record.bmBiSeat.seatname=result[1];
                     }, function(reason) {  
                         console.log(reason);  
                     }); 

                 };
                 
                 $scope.showFloorList = function() {
//                 	 if($scope.record.biHouseinfo.buildingid == null || $scope.record.biHouseinfo.buildingid == ''){
//               			alert('请选择楼栋');
//               			$('#houseName').focus();
//               			return;
//               		}
            		 	$scope.items = [];
                         var modalInstance = $modal.open({
                             templateUrl : 'bmFloorList.html',//script标签中定义的id
                             controller : 'bmFloorListCtrl',//modal对应的Controller
                             size: 'lg',
                             resolve : {
                            	 regionId : function() {  
                                     return $scope.record.biHouseinfo.regionid;  
                                 },
                              buildingId : function(){
                             	 	return $scope.record.biHouseinfo.buildingid;
                              	},
                              seatId : function(){
                            	  return $scope.record.biHouseinfo.seatid;
                              }
                             }
                         });
                         
                         modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
                              
                         });  
                         modalInstance.result.then(function(result) { 
                        	$scope.record.bmBiFloor = {};
                         	$scope.record.biHouseinfo.floorid = result[0];
                         	$scope.record.bmBiFloor.floorname=result[1];
                         }, function(reason) {  
                             console.log(reason);  
                         }); 

                     };
            
    }]);
    
    
    //楼栋新增模态框
    app.controller('bmBuildingInsertCtrl', function($scope, $rootScope, $modal,$modalInstance,regionid) {
        $scope.record = {};
        $scope.record.status = '1';
        $scope.insertBuilding = function(){
            
            $scope.record.regionid = regionid;
            
            var m = $scope.record;
            if(m.regionid == null){
                alert("请选择区域！");
            }else if(m.regionid != null){
                $scope.isDisabled = true;
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
                    url : '/dac/bm/building/insertOrUpdate',
                    data: angular.toJson($scope.record)
                }).then(function(result){
                    if(result.httpCode ==200){//成功
                      $scope.record = result.data;
                      $modalInstance.close($scope.record); 
                   }else{
                      toaster.clear('*');
                      toaster.pop('error', '', result.msg);
                      $scope.isDisabled = false;
                    }
                });
            }
        }
        
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
    });
    
    //楼座新增模态框
    app.controller('bmSeatInsertCtrl', function($scope, $rootScope, $modal,$modalInstance,items) {
        $scope.record = {};
        $scope.record.status = '1';
        $scope.insertSeat = function(){
            
            $scope.record.regionid = items.regionid;
            $scope.record.buildingid = items.buildingid;
            
            var m = $scope.record;
//            console.log("55555"+angular.toJson($scope.record));
            if(m.regionid == null){
                alert("请选择区域！");
            }else if(m.buildingid == null){
                alert("请选择楼栋！");
            }else if(m.regionid != null && m.buildingid != null){
                $scope.isDisabled = true;
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
                    url : '/dac/bm/seat/insertOrUpdate',
                    data: angular.toJson($scope.record)
                }).then(function(result){
                  if(result.httpCode ==200){//成功
                    $scope.record = result.data;
                    $modalInstance.close($scope.record); 
                  }else{
                    toaster.clear('*');
                    toaster.pop('error', '', result.msg);
                    $scope.isDisabled = false;
                  }
                });
            }
           
        }
         
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
    });
    
    //楼层新增模态框
    app.controller('bmFloorInsertCtrl', function($scope, $rootScope, $modal,$modalInstance,items) {
        $scope.record = {};
        $scope.record.status = '1';
        $scope.insertFloor = function(){
            
            $scope.record.regionid = items.regionid;
            $scope.record.buildingid = items.buildingid;
            $scope.record.seatid = items.seatid;
            
            var m = $scope.record;
            if(m.regionid == null){
                alert("请选择区域！");
            }else if(m.buildingid == null){
                alert("请选择楼栋！");
            }else if(m.seatid == null){
                alert("请选择楼座！");
            }else if(m.regionid != null && m.buildingid != null && m.seatid != null){
                $scope.isDisabled = true;
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    contentType:'application/json;charset=UTF-8',
                    url : '/dac/bm/floor/insertOrUpdate',
                    data: angular.toJson($scope.record)
                }).then(callback);
            }
            function callback(result) {
                if(result.httpCode ==200){//成功
                    $scope.record = result.data;
                    $modalInstance.close($scope.record); 
                }else{
                    toaster.clear('*');
                    toaster.pop('error', '', result.msg);
                    $scope.isDisabled = false;
                }
            }
        }
         
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
    });
    
    //地市模态框
    app.controller('bmCityListCtrl', function($scope, $rootScope, $modal,$modalInstance,items) {
        $scope.param = {};
        
        $scope.search = function () {
            
            $scope.param.type='CITIES';
            if($scope.pageFlag != 1){//未点击翻页
                   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
                }else{//点击翻页
                   $scope.pageFlag = 2;//将开关值设置为2
                }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/dic/queryDicList',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                
                if (result.httpCode == 200) {
                    $scope.pageInfo = result;
//                  console.log(result);
//                  console.log("=====》》》》");
                } else {
                    $scope.msg = result.msg;
                }
                $scope.$apply();
            });
        }
        $scope.search();
        
        $scope.select = function(id_,code_text,code_) {  
            $scope.params = [];
            $scope.params[0]=id_;
            $scope.params[1]=code_text;
            $scope.params[2]=code_;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
            $scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });
    
    //区县模态框
    app.controller('bmAreaListCtrl', function($scope, $rootScope, $modal,$modalInstance,items) {
        $scope.param = {};
        
        $scope.search = function () {
            
            $scope.param.type='AREAS';
            $scope.param.parent_code = items.parent_code;
            if($scope.pageFlag != 1){//未点击翻页
                   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
                }else{//点击翻页
                   $scope.pageFlag = 2;//将开关值设置为2
                }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/dic/queryDicList',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                
                if (result.httpCode == 200) {
                    $scope.pageInfo = result;
                    console.log(result);
                } else {
                    $scope.msg = result.msg;
                }
                $scope.$apply();
            });
        }
        $scope.search();
        
        $scope.select = function(id_,code_text,code_) {  
            $scope.params = [];
            $scope.params[0]=id_;
            $scope.params[1]=code_text;
            $scope.params[2]=code_;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
            $scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });

    //乡镇街道模态框
    app.controller('bmStreetListCtrl', function($scope, $rootScope, $modal,$modalInstance,items) {
        $scope.param = {};
        
        $scope.search = function () {
            
            $scope.param.type='STREETS';
            $scope.param.parent_code = items.parent_code;
//          console.log("=======》"+$scope.param.parent_code);
            if($scope.pageFlag != 1){//未点击翻页
                   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
                }else{//点击翻页
                   $scope.pageFlag = 2;//将开关值设置为2
                }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType:'application/json;charset=UTF-8',
                url : '/dic/queryDicList',
                data: angular.toJson($scope.param)
            }).then(function(result) {
                
                if (result.httpCode == 200) {
                    $scope.pageInfo = result;
                    console.log($scope.pageInfo);
                } else {
                    $scope.msg = result.msg;
                }
                $scope.$apply();
            });
        }
        $scope.search();
        
        $scope.select = function(id_,code_text,code_) {  
            $scope.params = [];
            $scope.params[0]=id_;
            $scope.params[1]=code_text;
            $scope.params[2]=code_;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
            $scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });
 
    app.controller('bmBuildingListCtrl', function($scope, $rootScope, $modal,$modalInstance,regionId) {
        $scope.param = { };
        $scope.param.regionId = regionId;
		$scope.search = function () {
	        $scope.loading = true;
	        if($scope.pageFlag != 1){//未点击翻页
			  	   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
			  	}else{//点击翻页
			  	   $scope.pageFlag = 2;//将开关值设置为2
			  	}
			$.ajax({
				type: 'PUT',
	            dataType: 'json',
				contentType:'application/json;charset=UTF-8',
				url : '/dac/bm/building/list',
				data: angular.toJson($scope.param)
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
		
		$scope.search();
		
        $scope.select = function(id,name,address) {
        	$scope.params = [];
        	$scope.params[0]=id;
        	$scope.params[1]=name;
            $scope.params[2]=address;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
        	$scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });
   
    app.controller('bmSeatListCtrl', function($scope, $rootScope, $modal,$modalInstance,regionId,buildingId) {
        $scope.param = { };
        $scope.param.regionId = regionId;
        $scope.param.buildingId = buildingId;
        console.log('regionid:'+regionId+','+'buildingId:'+buildingId);
		$scope.search = function () {
	        $scope.loading = true;
	        if($scope.pageFlag != 1){//未点击翻页
			  	   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
			  	}else{//点击翻页
			  	   $scope.pageFlag = 2;//将开关值设置为2
			  	}
			$.ajax({
				type: 'PUT',
	            dataType: 'json',
				contentType:'application/json;charset=UTF-8',
				url : '/dac/bm/seat/list',
				data: angular.toJson($scope.param)
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
		
		$scope.search();
		
        $scope.select = function(id,name) {  
        	$scope.params = [];
        	$scope.params[0]=id;
        	$scope.params[1]=name;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
        	$scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });
    
    app.controller('bmFloorListCtrl', function($scope, $rootScope, $modal,$modalInstance,regionId,buildingId,seatId) {
        $scope.param = { };
        $scope.param.regionId = regionId;
        $scope.param.buildingId = buildingId;
        $scope.param.seatId = seatId;
        console.log('regionid:'+regionId+','+'buildingId:'+buildingId+',seatId:'+seatId);
		$scope.search = function () {
	        $scope.loading = true;
	        if($scope.pageFlag != 1){//未点击翻页
			  	   $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
			  	}else{//点击翻页
			  	   $scope.pageFlag = 2;//将开关值设置为2
			  	}
			$.ajax({
				type: 'PUT',
	            dataType: 'json',
				contentType:'application/json;charset=UTF-8',
				url : '/dac/bm/floor/list',
				data: angular.toJson($scope.param)
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
		
		$scope.search();
		
        $scope.select = function(id,name) {  
        	$scope.params = [];
        	$scope.params[0]=id;
        	$scope.params[1]=name;
            $modalInstance.close($scope.params);  
        };  
        $scope.cancel = function() {  
            $modalInstance.dismiss('cancel');  
        }; 
        
        $scope.clear = function(){
        	$scope.select('','');
        }
        
     // 翻页
      $scope.pagination = function (page) {
            $scope.param.pageNum=page;
            $scope.pageFlag = 1;//将开关值设置为1
            $scope.search();
      };
    });

app.controller('bmFloorListCtrl', function($scope, $rootScope, $modal,$modalInstance,regionId,buildingId,seatId) {
    $scope.param = { };
    $scope.param.regionId = regionId;
    $scope.param.buildingId = buildingId;
    $scope.param.seatId = seatId;
    console.log('regionid:'+regionId+','+'buildingId:'+buildingId+',seatId:'+seatId);
    $scope.search = function () {
        $scope.loading = true;
        if($scope.pageFlag != 1){//未点击翻页
            $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
        }else{//点击翻页
            $scope.pageFlag = 2;//将开关值设置为2
        }
        $.ajax({
            type: 'PUT',
            dataType: 'json',
            contentType:'application/json;charset=UTF-8',
            url : '/dac/bm/floor/list',
            data: angular.toJson($scope.param)
        }).then(function(result) {
            $scope.loading = false;
            if (result.httpCode == 200) {
                $scope.pageInfo = result;
            } else {
                $scope.msg = result.msg;
            }
            $scope.$apply();
        });
    }

    $scope.search();

    $scope.select = function(id,name) {
        $scope.params = [];
        $scope.params[0]=id;
        $scope.params[1]=name;
        $modalInstance.close($scope.params);
    };
    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
    };

    $scope.clear = function(){
        $scope.select('','');
    }

    // 翻页
    $scope.pagination = function (page) {
        $scope.param.pageNum=page;
        $scope.pageFlag = 1;//将开关值设置为1
        $scope.search();
    };
});

//警务区模态框控制器
app.controller('jwqModalCtrl', function($scope, $rootScope, $modal,$modalInstance) {

    // 查询条件、参数，用于传递给后台使用
    $scope.param = {};
    // 若为1则显示房东复选框的模态框；若为0则显示租客单选框的模态框。
    $scope.tag = 0;

    $scope.search = function() {
        $scope.loading = true;
        if($scope.pageFlag != 1){//未点击翻页
            $scope.param.pageNum=1;//将页码设置为1，即跳转回第一页
        }else{//点击翻页
            $scope.pageFlag = 2;//将开关值设置为2
        }
        $.ajax({
            type : 'POST',
            dataType : 'json',
            contentType : 'application/json;charset=UTF-8',
            url : 'dac/userManager/jwqdm/list',
            data : angular.toJson($scope.param)
        }).then(function(result) {
            $scope.loading = false;
            if (result.httpCode == 200) {
                $scope.pageInfo = result;
                //console.log(result);
            } else {
                $scope.msg = result.msg;
            }
            $scope.$apply();
        });
    }

    // 调用查询函数
    $scope.search();

    $scope.selectjwq = function(jwqdm,jwqmc) {
        $scope.params = [];
        $scope.params[1] = jwqdm;
        $scope.params[2] = jwqmc;
        // 这里需要将复选框选中的属性取到，然后交给$modalInstance回显到修改页面
        // 修改页面将复选框传来的值再传给后台
        $modalInstance.close($scope.params);
    };

    // 取消
    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
    };

    // 翻页
    $scope.pagination = function(page) {
        $scope.param.pageNum = page;
        $scope.pageFlag = 1;//将开关值设置为1
        $scope.search();
    };


});